package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController

@Api(tags = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 分页查询护理计划数据
     *
     * @param pageNum
     * @param pageSize
     * @param status
     * @param planName
     * @return
     */
    @GetMapping("/nursing/plan/search")
    @ApiOperation(value = "分页查询护理计划数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "planName", value = "护理计划名称", required = false, dataType = "String", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(Integer pageNum,
                                                                       Integer pageSize,
                                                                       Integer status,
                                                                       String planName
    ) {
        PageResponse<NursingPlan> pageInfo = nursingPlanService.selectByPage(pageNum, pageSize, status, planName);
        return success(pageInfo);
    }

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @GetMapping("/nursing/plan")
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlanVo> > findAll() {
        List<NursingPlanVo>  findAll = nursingPlanService.finAll();
        return success(findAll);
    }

    /**
     * 新增查询计划
     *
     * @param nursingPlanDto
     * @return
     */
    @PostMapping("/nursing/plan")
    @ApiOperation(value = "新增查询计划")
    public ResponseResult insertPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.insertPlan(nursingPlanDto);
        return success();
    }

    /**
     * 根据id查询项目计划
     *
     * @param id
     * @return
     */
    @GetMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Long id) {
        NursingPlanVo vo = nursingPlanService.selectById(id);
        return success(vo);
    }

    @PutMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id修改计划")
    public ResponseResult updateById(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateById(id, nursingPlanDto);
        return success();
    }

    /**
     * 根据id删除护理计划
     *
     * @param id
     * @return
     */
    @DeleteMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id删除护理计划")
    public ResponseResult deleteById(@PathVariable Long id) {
        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/nursing/{id}/status/{status}")
    @ApiOperation(value = "启用禁用护理计划")
    public ResponseResult openPlanStatus(@PathVariable Long id, @PathVariable Long status) {
        nursingPlanService.openPlanStatus(id, status);
        return success();
    }

}

